package com.xxx.mch.controller;

import com.xxx.mch.domain.dto.AllowanceScoreDto;
import com.xxx.mch.domain.dto.PersonalScoreDto;
import com.xxx.mch.domain.po.User;
import com.xxx.mch.domain.request.ConfirmScoreRequest;
import com.xxx.mch.service.impl.UserServiceImpl;
import com.xxx.mch.utils.WrapMapper;
import com.xxx.mch.utils.Wrapper;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部门管理
 * @author FengHaixin
 * @description 一句话描述该文件的用途
 * @date 2020-02-25
 */
@RestController
@RequestMapping ("user")
@Slf4j
public class UserController
{

    @Autowired
    private UserServiceImpl userServiceImpl;


    @GetMapping (value="update",produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<String> updateUser()
    {
        log.info("执行用户同步操作...");
        userServiceImpl.insertOrUpdate();
        return WrapMapper.ok();
    }

    @GetMapping (value = "/{deptId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<List<User>> getUser(@PathVariable Integer deptId)
    {
        List<User> list = userServiceImpl.getUserList(deptId);
        return WrapMapper.ok(list);
    }


    @ApiOperation (value = "查询个人的得分汇总信息")
    @GetMapping (value = "/score/summary", produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<PersonalScoreDto> summary(@RequestParam("uid") String uid, @RequestParam("month") String month)
    {
        return WrapMapper.ok(userServiceImpl.scoreSummary(uid, month));
    }


    @ApiOperation (value = "个人确认评分正确不正确接口")
    @PostMapping (value = "/confirmScore",consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<String> confirmScore(@Valid @RequestBody ConfirmScoreRequest request)
    {
        userServiceImpl.confirmScore(request);
        return WrapMapper.ok();
    }


    @ApiOperation (value = "查询所有的用户信息", notes = "")
    @GetMapping (value = "all", produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<List<User>> getUser()
    {
        List<User> list = userServiceImpl.allUser();
        return WrapMapper.ok(list);
    }

    @ApiOperation (value = "查询用户的定量分明细", notes = "")
    @GetMapping (value = "allowanceScore", produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<List<AllowanceScoreDto>> getAllowanceScore(@RequestParam("uid") String uid, @RequestParam("month") String month)
    {
        List<AllowanceScoreDto> allowanceScore = userServiceImpl.getAllowanceScore(uid, month);
        return WrapMapper.ok(allowanceScore);
    }
}
